/*
 *  * Copyright  rocedu@BESTI   rocedu@qq.com   All rights reserved.
 *   *
 *    * 鏂囦欢鍒涘缓绋嬪簭锛屾帴鍙椾竴涓懡浠よ鍙傛暟浣滀负鏂囦欢鍚嶅苟鍒涘缓璇ユ枃浠躲€?
 *     * 濡傛灉鍙傛暟涓嶆纭垨鏂囦欢鍒涘缓澶辫触锛岀▼搴忓皢鎵撳嵃閿欒淇℃伅銆?
 *      */

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <linux/limits.h>

int main(int argc, char *argv[]) {
	    char filename[PATH_MAX] = {0};  // 鐢ㄤ簬瀛樺偍鏂囦欢鍚嶇殑瀛楃鏁扮粍锛屽垵濮嬪寲涓?

	        // 妫€鏌ュ懡浠よ鍙傛暟鐨勬暟閲?
		     if (argc != 2) {
		             fprintf(stderr, "You must supply a filename as an argument \n");
		                     return 1;  // 杩斿洖1琛ㄧず閿欒
		                         }
		
		                             // 瀹夊叏鍦版嫹璐濆懡浠よ鎻愪緵鐨勬枃浠跺悕鍒癴ilename鏁扮粍
		                                 strncpy(filename, argv[1], sizeof(filename) - 1);
		                                     // 纭繚鏈€鍚庝竴涓瓧绗︿负'\0'浠ラ伩鍏嶅瓧绗︿覆鏈粓姝?
		                                         filename[sizeof(filename) - 1] = '\0';
		
		                                             // 鍒涘缓鏂囦欢骞惰缃潈闄愪负0644锛岃嫢澶辫触鍒欐墦鍗伴敊璇俊鎭?
		                                                 if (creat(filename, 00644) == -1) {
		                                                         perror("Can't create file");  // 浣跨敤perror鎵撳嵃绯荤粺閿欒淇℃伅
		                                                                 return 1;  // 杩斿洖1琛ㄧず閿欒
		                                                                     }
		
		                                                                         return 0;  // 杩斿洖0琛ㄧず鎴愬姛
		                                                                         }
		
		                                                                        
